package avortep.synchro;


public class DBFirebirdSqlReader extends DBSqlReader {

	

	public DBFirebirdSqlReader() {
		StringBuilder sb = new StringBuilder();
		this.schemaName = null;
		this.sqlGetTables = 
			" SELECT RDB$RELATION_NAME as "
			+this.tableName
			+" FROM RDB$RELATIONS"
			+" WHERE RDB$RELATION_TYPE = 0 and (rdb$system_flag is null or rdb$system_flag = 0)";		
		this.sqlGetViews = 
			" SELECT RDB$VIEW_SOURCE as "
			+viewSourceName
			+", RDB$RELATION_NAME as "
			+this.tableName
			+" FROM rdb$relations"
			+" WHERE rdb$view_blr is not null and (rdb$system_flag is null or rdb$system_flag = 0)";
		sb.append(" SELECT a.RDB$FIELD_NAME as ");
		sb.append(this.columnName);
		sb.append(", a.RDB$RELATION_NAME as ");
		sb.append(this.tableName);
		sb.append(", c.RDB$TYPE_NAME as ");
		sb.append(this.typeName);
		sb.append(", a.RDB$DEFAULT_SOURCE as ");
		sb.append(this.defaultSource);
		sb.append(", a.RDB$NULL_FLAG as ");
		sb.append(this.isNullable);
		sb.append(", b.RDB$VALIDATION_SOURCE as ");
		sb.append(this.checkClause);
		sb.append(" FROM RDB$RELATION_FIELDS a, RDB$FIELDS b, RDB$TYPES c");
		sb.append(" WHERE a.RDB$SYSTEM_FLAG=0 and b.RDB$FIELD_NAME=a.RDB$FIELD_SOURCE and (c.RDB$TYPE=b.RDB$FIELD_TYPE and c.RDB$FIELD_NAME = 'RDB$FIELD_TYPE')");
		sb.append(" ORDER BY a.RDB$RELATION_NAME, a.RDB$FIELD_POSITION");
		this.sqlGetColumns = sb.toString();

	}
}
